var e = getApp(), a = require("../../339469457B99569C55F201426D89DBD0.js"), t = require("../../38034BA77B99569C5E6523A090A9DBD0.js"), o = a.getImgCheckurl(), i = a.getImage2asciiurl();

Page({
    data: {
        motto: "图片转字符图片",
        images: {},
        info: "",
        img: "",
        userInfo: {},
        backUserInfo: {},
        hasUserInfo: !1,
        openId: "",
        nickName: "",
        remark: "原图宽高不要过大哦，目前base64没有压缩，过大小程序会解析失败",
        canIUse: wx.canIUse("button.open-type.getUserInfo"),
        token: null
    },
    onShareAppMessage: function() {
        return {
            title: "图片转字符图片",
            path: "/pages/image2ascii/image2ascii",
            success: function(e) {
                "shareAppMessage:ok" == e.errMsg && wx.showToast({
                    title: "分享成功",
                    icon: "success",
                    duration: 500
                });
            },
            fail: function(e) {
                "shareAppMessage:fail cancel" == e.errMsg && wx.showToast({
                    title: "分享取消",
                    icon: "loading",
                    duration: 500
                });
            }
        };
    },
    clear: function(e) {
        console.info(e), wx.clearStorage();
    },
    bindViewTap: function() {
        wx.navigateTo({
            url: "../logs/logs"
        });
    },
    uploads: function() {
        var e = this;
        wx.chooseImage({
            count: 1,
            sizeType: [ "compressed" ],
            sourceType: [ "album", "camera" ],
            success: function(a) {
                a.tempFiles[0].size > 1048576 ? wx.showToast({
                    title: "图片文件过大哦",
                    icon: "none",
                    mask: !0,
                    duration: 1500
                }) : (e.setData({
                    img: a.tempFilePaths[0],
                    info: ""
                }), setTimeout(function() {
                    wx.showLoading({
                        title: "努力转换中...",
                        mask: !0
                    });
                }, 500), wx.uploadFile({
                    url: o,
                    filePath: a.tempFilePaths[0],
                    header: {
                        "content-type": "multipart/form-data"
                    },
                    name: "file",
                    formData: {
                        code: "XSYD"
                    },
                    success: function(t) {
                        var o = JSON.parse(t.data);
                        "0" == o.errcode ? wx.uploadFile({
                            url: i,
                            filePath: a.tempFilePaths[0],
                            header: {
                                "content-type": "multipart/form-data"
                            },
                            name: "file",
                            formData: {
                                openId: e.data.openId,
                                nickName: e.data.nickName
                            },
                            success: function(a) {
                                wx.hideLoading();
                                var t = a.data, o = JSON.parse(t);
                                console.log(o), 0 == o.code ? (console.log(0 == o.code), e.setData({
                                    img: "data:image/jpg;base64," + o.image
                                })) : "1" == o.code ? e.setData({
                                    info: "Sorry " + o.msg
                                }) : e.setData({
                                    info: "Sorry 小程序远走高飞了"
                                });
                            },
                            fail: function(e) {
                                wx.hideLoading(), wx.showModal({
                                    title: "温馨提示",
                                    content: "Sorry 小程序离家出走了",
                                    showCancel: !1
                                });
                            }
                        }) : "87014" == o.errcode ? (wx.hideLoading(), wx.showModal({
                            content: "存在敏感内容，请更换图片",
                            showCancel: !1,
                            confirmText: "明白了"
                        }), e.setData({
                            img: null
                        })) : (wx.hideLoading(), wx.showModal({
                            content: "其他错误，稍后再试",
                            showCancel: !1,
                            confirmText: "明白了"
                        }));
                    }
                }));
            }
        });
    },
    onLoad: function() {
        var a = this, o = e.data.openId;
        this.setData({
            openId: o
        }), t.tokenRequest({
            success: function(e) {
                a.setData({
                    token: e.access_token
                });
            }
        });
    },
    preview: function(e) {
        var a = this;
        "" == a.data.img ? wx.showToast({
            title: "快选择图片吧",
            icon: "none",
            mask: !0,
            duration: 1e3
        }) : wx.previewImage({
            urls: [ a.data.img ],
            current: a.data.img
        });
    }
});